<extend name="./Application/Admin/View/common/base.html" />
<block name="crumb">
    <span class="c-gray en">&gt;</span> 规格管理
    <span class="c-gray en">&gt;</span> 添加规格
</block>
<block name="content">
    <form class="form form-horizontal" id="add-parameter">
        <input type="hidden" id="type" value="1">
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>规格名称：</label>
            <div class="formControls col-xs-8 col-sm-3">
                <input type="text" class="input-text radius" name="p_name" >
            </div>
        </div>

        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>所属商品模型：</label>
            <div class="formControls col-xs-8 col-sm-2" >
                <span class="select-box">
                <select name="model" class="select">
                    <volist name="models" id="model" >
                        <option value="{$model['id']}">
                            {$model['m_name']}
                        </option>
                    </volist>
                </select>
                </span>
            </div>
        </div>
        <div class="row cl" id="optional">
            <label class="form-label col-xs-4 col-sm-2">规格项：</label>
            <div class="formControls col-xs-8 col-sm-3">
                <textarea name="parameter_val" class="textarea" placeholder="一行代表一个规格项！"></textarea>
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-2"></label>
            <button id="save" class="btn btn-secondary radius" type="submit"><i class="Hui-iconfont">&#xe632;</i> 保存</button>
        </div>
    </form>
</block>
<block name="js">
    <script type="text/javascript">

        $(function () {

            //点击保存规格
            $('#save').click(function () {
                $('#add-parameter').validate({
                    rules: {
                        p_name: {required: true, minlength: 2},
                        parameter_val: {required: true}
                    },
                    messages: {
                        p_name: {required: '请填写规格名称！', minlength: '规格名称不少于2位！'},
                        parameter_val: {required: '请填写规格项！'}
                    },
                    submitHandler: function (form) {
                        $(form).ajaxSubmit({
                            type: 'post',
                            url: "{:U('Parameter/addParameter')}",
                            data: {
                                p_name: $("input[name='p_name']").val(),
                                model_id: $(".select option:selected").val(),
                                parameter_val: $("textarea[name='parameter_val']").val()
                            },
                            beforeSend: function () {
                                layer.msg('商品规格添加中..', {icon: 16,time:0});
                            },
                            success: function (msg) {
                                layer.msg('商品规格添加成功！', {icon: 6,time:1000});
                                setTimeout(function(){ window.location.href = "{:U('Parameter/index')}"; }, 1000);
                            }
                        });
                    }
                });
            });
        });


    </script>
</block>
